package com.ciwong.epaper.common;

import android.content.Context;
import android.widget.Toast;

import com.ciwong.epaper.modules.me.bean.MyWork;
import com.ciwong.epaper.modules.me.bean.WorkContents;
import com.ciwong.mobilelib.ui.BaseActivity;
import com.ciwong.mobilelib.utils.ToastUtil;
import com.ciwong.mobilelib.utils.toast.ToastCustomView;
import com.ciwong.epaper.widget.toast.ZToast;

import java.text.SimpleDateFormat;

/**
 * Created by Administrator on 2018/6/25.
 */

public enum CheckIsExamForDetail {
    INSTANCE;
    private String contentId = null;
    private long effectiveDate = -1;
    private long nowDate = -1;
    private int examMode = 0;
    private int seeWorkMode = 0;
    private int submitMode = 0;
    private static final int FLAGE_NO_TOAST = -1;
    private static final int FLAGE_SHOW_DELAY = 0;
    private static final int FLAGE_SHOW_SUBMIT_SUCCESS = 1;

    private CheckIsExamForDetail() {
    }

    /**
     * @param serverTime  截止时间
     * @param nowDate     服务器时间
     * @param examMode    作业模式：0 练习模式，1为机房模式，2考试模式
     * @param seeWorkMode 查看类型：0 提交立马能查看，1截止时间到后查看
     * @param submitMode  补交类型：0 截止时间到后能补交 1截止时间到后不能补交
     * @return false 代表不可以查看详情 true 可以查看详情
     */
    public void checkExamATime(long serverTime, String contentId, long nowDate, int examMode, int seeWorkMode, int submitMode) {
        this.effectiveDate = serverTime;
        this.contentId = contentId;
        this.nowDate = nowDate;
        this.examMode = examMode;
        this.seeWorkMode = seeWorkMode;
        this.submitMode = submitMode;
    }

    /**
     * @param mActivity
     * @param contentId 作为是否为作业页面进来的标识
     * @param flagToast
     * @return true 可以查看 false 不可以查看
     */
    public boolean isOrNotWatchDetails(BaseActivity mActivity, String contentId, int flagToast) {
        if (contentId == null && contentId.equals("")) return true;
        if (contentId.equals(this.contentId)) {
            if (seeWorkMode == 0) {
                return true;
            } else {
                if (nowDate < effectiveDate) {
                    SimpleDateFormat formatter = new SimpleDateFormat("M月d号 H:mm");
                    String time = formatter.format(effectiveDate * 1000);
                    switch (flagToast) {
                        case FLAGE_NO_TOAST:
                            break;
                        case FLAGE_SHOW_DELAY:
                            ZToast.makeText(mActivity, time + "后才可查看哦", ZToast.LENGTH_SHORT).show();
                            break;
                        case FLAGE_SHOW_SUBMIT_SUCCESS:
                            ZToast.makeText(mActivity, "提交成功," + time + "后才可查看哦", ZToast.LENGTH_SHORT).show();
                            break;

                    }
                    return false;
                }
            }
        }
        return true;//不是考试用书或者不是从作业页面进来或者不是从对应的作业页面进入
    }

    /**
     * 是否可以做作业
     *
     * @param mActivity
     * @param myWork      作业
     * @param workContent 作业内容
     * @param workType    作业类型
     * @return true 可以 false 不可以
     */
    public boolean isOrNotDowork(BaseActivity mActivity, MyWork myWork, WorkContents workContent, int workType) {
        if (workType == 1) {
            return true;
        }
        //现在时间
        long nowTime = workContent.getNowDate();
        //截止时间
        long effectiveDate = myWork.getEffectiveDate();

        if (workContent == null) {
            return false;
        }
        // 作业模式：0 练习模式，1为机房模式，2考试模式
        int examMode = workContent.getExamMode();
        // 查看类型：0 提交立马能查看，1截止时间到后查看
        int seeWorkMode = workContent.getSeeWorkMode();
        // 补交类型：0 截止时间到后能补交 1截止时间到后不能补交
        int submitMode = workContent.getSubmitMode();
        if (examMode == 2) {
            if (submitMode == 0) {
                return true;
            } else {
                if (nowTime >= effectiveDate) {
                    ZToast.makeText(mActivity, "考试截止你已无法继续考试", ZToast.LENGTH_SHORT).show();
                    return false;
                } else {
                    return true;
                }
            }
        } else if (examMode == 1) {
            ZToast.makeText(mActivity, "机房考试你已缺考无法继续考试", ZToast.LENGTH_SHORT).show();
            return false;
        }
        return true;
    }

    /**
     * 是否可以查看作业
     *
     * @param mActivity
     * @param myWork      作业
     * @param workContent 作业内容
     * @param workType    作业类型
     * @return true 可以 false 不可以
     */
    public boolean isOrNotSeeWorkAnswer(BaseActivity mActivity, MyWork myWork, WorkContents workContent, int workType) {
        if (workType == 1) {
            return true;
        }
        //现在时间
        long nowTime = workContent.getNowDate();
        //截止时间
        long effectiveDate = myWork.getEffectiveDate();

        if (workContent == null) {
            return false;
        }
        // 作业模式：0 练习模式，1为机房模式，2考试模式
        int examMode = workContent.getExamMode();
        // 查看类型：0 提交立马能查看，1截止时间到后查看
        int seeWorkMode = workContent.getSeeWorkMode();
        // 补交类型：0 截止时间到后能补交 1截止时间到后不能补交
        int submitMode = workContent.getSubmitMode();
        if (seeWorkMode == 0) {
            return true;
        } else {
            if (nowTime < effectiveDate) {
                SimpleDateFormat formatter = new SimpleDateFormat("M月d号 H:mm");
                String time = formatter.format(effectiveDate * 1000);
                ZToast.makeText(mActivity, time + "后才可查看哦", ZToast.LENGTH_SHORT).show();
                return false;
            }
        }
        return true;
    }
}
